<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    class Father {
      constructor(x, y) {
        // this 是哪个对象? 子
        this.x = x;
        this.y = y;
      }
      sum() {
        console.log(this.x + this.y);

      }
    }
    class Son extends Father {
      constructor(x, y) {
        super(x, y); // 调用了父类中的构造函数
        // this.x = x
        // this.y = y
        // 如果在构造函数中写代码(this), 必须先写super(), 这是语言的规则
        // Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
        // xxx of undefined
      }
    }
    var son = new Son(1, 2);
    var son1 = new Son(11, 22);
    son.sum();
    son1.sum();

  </script>
</body>

</html>